<div ng-controller="FieldManListC">
    <div class="bg-light lter b-b wrapper-md">
        <h3 class="m-n font-thin h3">驻厂计划单</h3>
    </div>
    <div class="bg-light lter b-b wrapper-md" style="margin-bottom: 10px">
        <div class="row">
            <div class="col-xs-12 input-group" style="padding: 0px 15px 5px">
                <input type="text" class="form-control" id="findname" placeholder="按名称查找" ng-model="findname">
                    <span class="input-group-btn">
                        <button class="btn btn-default"  type="button" ng-click="find('')">查找</button>
                    </span>
            </div>
        </div>
        <div class="row">
            <div class="col-xs-8 btn-group dropdown" dropdown>
                <button class="btn btn-default" dropdown-toggle>按计划单状态查看 <span class="caret"></span></button>
                <ul class="dropdown-menu">
                    <li ng-click="find('')"><a href>查看全部</a></li>
                    <li ng-click="find(0)"><a href>待确认</a></li>
                    <li ng-click="find(1)"><a href>驻厂确认</a></li>
                    <li ng-click="find(2)"><a href>已发货</a></li>
                    <li ng-click="find(3)"><a href>已收货</a></li>
                    <li ng-click="find(4)"><a href>已结算</a></li>
                    <li ng-click="find(5)"><a href>完结</a></li>
                    <li ng-click="find(6)"><a href>取消</a></li>
                    <li ng-click="find(7)"><a href>审核通过</a></li>
                    <li ng-click="find(8)"><a href>已退货</a></li>
                    <li ng-click="find(9)"><a href>已退款</a></li>
                </ul>
            </div>
            <div class="col-xs-4 btn-group">
                <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    按计划单类型查看 <span class="caret"></span>
                </button>
                <ul class="dropdown-menu">
                    <li ng-click="findType('')"><a href>查看全部</a></li>
                    <li ng-click="findType(4)"><a href>库提计划单</a></li>
                    <li ng-click="findType(0)"><a href>厂提计划单</a></li>
                    <li ng-click="findType(3)"><a href>自采计划单</a></li>
                </ul>
            </div>
        </div>
    </div>
    <!--<a ng-click="xxx($index)" ng-repeat="item in orders">-->
        <!--<div class="container-fluid" style="padding:10px auto; border-bottom: solid red 2px">-->
            <!--<div class="row">-->
                <!--<div style="text-align: center;" class="col-xs-12"><strong>客户名：</strong>{{item.Customer.Name}}</div>-->
            <!--</div>-->
            <!--<div class="row">-->
                <!--<div class="col-xs-6"><strong>地址：</strong>{{item.District.Name}}</div>-->
                <!--<div class="col-xs-6">-->
                    <!--<strong>状态：</strong>-->
                    <!--<span ng-if="item.State == 0">待确认</span>-->
                    <!--<span ng-if="item.State == 1">驻厂确认</span>-->
                    <!--<span ng-if="item.State == 2">已发货</span>-->
                    <!--<span ng-if="item.State == 3">已收货</span>-->
                    <!--<span ng-if="item.State == 4">已结算</span>-->
                    <!--<span ng-if="item.State == 5">完结</span>-->
                    <!--<span ng-if="item.State == 6">取消</span>-->
                    <!--<span ng-if="item.State == 7">审核通过</span>-->
                    <!--<span ng-if="item.State == 8">已退货</span>-->
                    <!--<span ng-if="item.State == 9">已退款</span>-->
                <!--</div>-->
            <!--</div>-->
            <!--<div class="row">-->
                <!--<div class="col-xs-6"><strong>金额/重量t：</strong>{{item.Total | number:2}}/{{item.Weight | number:3}}t</div>-->
                <!--<div class="col-xs-6">-->
                    <!--<strong>状态：</strong>-->
                    <!--<span ng-if="item.IsFullPayment">先款支付</span>&nbsp;-->
                    <!--<span ng-if="item.IsStandard">标件</span>-->
                <!--</div>-->
            <!--</div>-->
            <!--<div class="row">-->
                <!--<div class="col-xs-12"><strong>备注：</strong>{{item.Remarks}}</div>-->
            <!--</div>-->
            <!--<div class="row">-->
                <!--<div class="col-xs-12"><strong>创建时间：</strong>{{item.CreateTime}}</div>-->
            <!--</div>-->
        <!--</div>-->
    <!--</a>-->

    <a ng-click="xxx($index)" ng-repeat="item in orders">
        <div class="panel panel-default" style="margin-bottom: 10px">
            <div class="panel-heading">
                <h3 class="panel-title">{{item.Customer.Name}}</h3>
            </div>
            <div class="panel-body">
                <div class="row">
                    <div class="col-xs-6"><strong>地址：</strong>{{item.District.Name}}</div>
                    <div class="col-xs-6">
                        <strong>状态：</strong>
                        <span ng-if="item.State == 0">待确认</span>
                        <span ng-if="item.State == 1">驻厂确认</span>
                        <span ng-if="item.State == 2">已发货</span>
                        <span ng-if="item.State == 3">已收货</span>
                        <span ng-if="item.State == 4">已结算</span>
                        <span ng-if="item.State == 5">完结</span>
                        <span ng-if="item.State == 6">取消</span>
                        <span ng-if="item.State == 7">审核通过</span>
                        <span ng-if="item.State == 8">已退货</span>
                        <span ng-if="item.State == 9">已退款</span>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-6"><strong>金额/重量t：</strong>{{item.Total | number:2}}/{{item.Weight | number:3}}t</div>
                    <div class="col-xs-6">
                        <strong>标注：</strong>
                        <span ng-if="item.IsFullPayment">先款支付</span>&nbsp;
                        <span ng-if="item.IsStandard">标件</span>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12"><strong>备注：</strong>{{item.Remarks}}</div>
                </div>
            </div>
            <div class="panel-footer">{{item.CreateTime}}</div>
        </div>
    </a>
    <div class="row text-center">
        <div class="panel-heading" my-pagination get-page-data="getData" mypagedata="pageData"></div>
    </div>
</div>
<script>
    angular.module('app')
            .controller("FieldManListC", function ($scope, $state, $http,toSave) {
                $scope.pageData = {};
                $scope.pageData.Page = 0;
                $scope.state = "";
                $scope.type = "";
                $scope.findname = "";
                $scope.pageData.Rows = $scope.defPageRows;
                $scope.getData = function (p, r) {
                    if (p) {
                        p = p < 1 ? 1 : p;
                    } else p = 1;
                    if (r) {
                    } else r = $scope.defPageRows;
                    toSave.save_pages_lis(p, r);//保存当前页码和条数
                    console.log(toSave.get_pages());
                    $http({
                        url: "../api/FieldMan/Order?page=" + p + "&rows=" + r + "&state=" + $scope.state + "&type=" + $scope.type + "&name=" + $scope.findname,
                        method: "GET"
                    })
                            .then(function (res) {
                                console.log(res.data);
                                $scope.orders = res.data.Data;
                                $scope.pageData = res.data;
                            })
                            .then(function (error) {
                                if (error) {
                                    alert("数据获取失败");
                                }
                            });
                };
                $scope.xxx = function (index) {
                    $state.go('app.FieldMan_FieldManDetail', {
                        orderid: JSON.stringify($scope.orders[index].Id)
                    });
                };
                //加载数据
                // $scope.getData(1, $scope.pageData.Rows);
                $scope.find = function (state) {
                    if(state || state == ''){
                        $scope.state=state;
                    }
                    $scope.getData(1, $scope.pageData.Rows);
                     localStorage.setItem('c',$scope.state);
                    toSave.save_inputs();//点击查询先保存input里面的值
                    // console.log(localStorage.getItem("c"));
                };
                $scope.findType = function (type) {
                    if (type || type == '') {
                        $scope.State="";
                        console.log($scope.State)
                        $scope.type = type;
                        $scope.getData(1, $scope.pageData.Rows);
                    }
                };
                // console.log(localStorage.getItem("c"));    
                if (toSave.get_inputs('findname') ||localStorage.getItem("c")!=null ) {
                    $scope.findname=toSave.get_inputs('findname');//把保存该id名的值取出来赋值给input框
                    $scope.state=localStorage.getItem("c");
                    console.log(localStorage.getItem("c"));
                    console.log($scope.state);
                    $scope.getData(toSave.get_pages(), toSave.get_lis());
                }else{
                    $scope.getData(toSave.get_pages(), $scope.pageData.Rows);
                }
            })
</script>
<script src="js/services/toSave.js"></script>
